package com.ericom.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@Table(name = "promotion_card")
public class PromotionCard extends BaseObject {
	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("title", title).append("amount", amount)
				.append("valideFrom", valideFrom).append("valideTo", valideTo)
				.append("member", member).append("products", products)
				.append("orderAmount", orderAmount).append("status", status)
				.toString();
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof PromotionCard))
			return false;
		PromotionCard castOther = (PromotionCard) other;
		return new EqualsBuilder().append(id, castOther.id)
				.append(title, castOther.title).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).append(title).toHashCode();
	}

	@Column(name = "order_amount")
	public float getOrderAmount() {
		return orderAmount;
	}

	public void setOrderAmount(float orderAmount) {
		this.orderAmount = orderAmount;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Embedded
	public Amount getAmount() {
		return amount;
	}

	public void setAmount(Amount amount) {
		this.amount = amount;
	}

	@Column(name = "valide_from")
	public String getValideFrom() {
		return valideFrom;
	}

	public void setValideFrom(String valideFrom) {
		this.valideFrom = valideFrom;
	}

	@Column(name = "valide_to")
	public String getValideTo() {
		return valideTo;
	}

	public void setValideTo(String valideTo) {
		this.valideTo = valideTo;
	}


	@ManyToOne(cascade = { CascadeType.REFRESH })  
	@JoinColumn(name = "member_id")	
	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "promotion_product", joinColumns = { @JoinColumn(name = "prom_id") }, inverseJoinColumns = @JoinColumn(name = "prod_id"))
	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}

	private Long id;
	private String title;
	private Amount amount;
	private String valideFrom;
	private String valideTo;	
	private Member member;
	private Set<Product> products = new HashSet<Product>();
	private float orderAmount;
	private String status;

}
